Public Class UrlRewrite
    Implements IHttpModule
    Implements IHttpHandler


    Public Sub Init(ByVal context As HttpApplication) Implements IHttpModule.Init
        AddHandler context.BeginRequest, AddressOf OnBeginRequest
    End Sub

    Private Sub OnBeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        Dim app As HttpApplication
        app = CType(sender, HttpApplication)
        ProcessRequest(app.Context)
    End Sub

    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        Dim url As String = context.Request.Url.ToString
        Dim rawURL As String = context.Request.RawUrl.ToString


        If url.Contains("/tag/") Then
            context.RewritePath(rawURL.Replace("tag/", "tags.aspx?tag="), False)
        End If

    End Sub

    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return True
        End Get
    End Property

    Public Sub Dispose() Implements IHttpModule.Dispose

    End Sub

End Class
